package com.demo.crm.springboot3security.mapper;

import org.apache.ibatis.annotations.Mapper;

import com.demo.crm.springboot3security.entity.Permission;
import com.demo.crm.springboot3security.entity.table.Tables;
import com.mybatisflex.core.query.QueryWrapper;

@Mapper
public interface PermissionMapper extends BaseMapper<Permission> {
    /**
     * 根据权限名称查找权限
     * 
     * @param name 权限名称
     * @return 权限对象
     */
    default Permission findByName(String name) {
        return this.selectOneByQuery(QueryWrapper.create().where(Tables.PERMISSION.NAME.eq(name)));
    }

    /**
     * 根据权限键查找权限
     * 
     * @param permissionKey 权限键
     * @return 权限对象
     */
    default Permission findByPermissionKey(String permissionKey) {
        return this.selectOneByQuery(QueryWrapper.create().where(Tables.PERMISSION.KEY.eq(permissionKey)));
    }

    /**
     * 根据URL查找权限
     * 
     * @param url URL
     * @return 权限对象
     */
    default Permission findByUrl(String url) {
        return this.selectOneByQuery(QueryWrapper.create().where(Tables.PERMISSION.URL.eq(url)));
    }
}